package com.amado.course31;

import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class ListSort {
	public static void main(String[] args) {
		Student student1=new Student("张三",12);
		Student student2=new Student("李四",24);
		Student student3=new Student("小强",74);
		Student student4=new Student("王五",14);
		List list = Arrays.asList(student1,student2,student3,student4);
		print(list);
		System.out.println("排序以后------------------");
//		Collections.sort(list, new ComparatorImpl());
		//new 接口会生成一个匿名类，你要重写里面的所有的方法，跟实现接口比较：但的代码不能重用
		//如果只使用一次，可以使用匿名类
		list.sort(new ComparatorImpl());
		Collections.sort(list,new Comparator() {
			@Override
			public int compare(Object o1, Object o2) {
				// TODO Auto-generated method stub
				return 0;
			}
		});
		print(list);
	}
	public static void print(List list){
		Student tempStudent = null;
		for(Object obj:list){
			tempStudent = (Student)obj;
			System.out.println(tempStudent.getName()+"\t"+tempStudent.getAge());
		}
	}
}
